<?php

namespace App\Http\Controllers\Admin\Author;
use App\Http\Requests\BooksPostRequest;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CommentController extends Controller
{
    public function getIndex(Request $request)
    {
        $id = $request->session()->get('id');
        // return '评论专区';
        $comment = DB::table('hs_comment')
            ->join('hs_member','hs_member.id','=','hs_comment.publish_id')
            ->join('hs_articles','hs_comment.artid','=','hs_articles.id')
            ->join('hs_books','hs_articles.bid','=','hs_books.id')
            ->where(['hs_comment.status' => 0,'hs_articles.aid'=>$id])
            ->select('hs_comment.com_content','hs_member.name','hs_articles.title','hs_books.b_name','hs_comment.id','hs_comment.publish_id')
            ->get();
       
        return view('admin.author.comment.index',['comments'=>$comment]);
    }

    public function getReply($id,$name,$reply_id)
    {
        // var_dump($id);
        // var_dump($name);
        // die;
        // dd($reply_id);
        return view('admin.author.comment.reply',['id'=>$id,'name'=>$name,'reply_id'=>$reply_id]);    
    }

     public function postRestore(Request $request)
    {
        $data = $request->except('_token');
        $data['publish_id'] = $request->session()->get('id');
        $data['status'] = 1;
        $data['time'] = time();
        // dd($data);
        $res = DB::table('hs_comment')->insertGetId($data);
        if($res){
            DB::table('hs_comment')->where('id','=',$data['artid'])->update(['status'=>1]);
            return redirect('/admin/acomment/index')->with('success','回复成功');
        }
    }

    public function getRecycle($id)
    {
        // return '回收站';
        $res = DB::table('hs_comment')->where('id','=',$id)->update(['status'=>2]);
        if($res){
            return redirect('/admin/acomment/index')->with('success','回收成功');
        }
    }


}
